package edu.tgc.web.controller.teaching;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;

import org.abyss.common.web.controller.easyui.CommonCrudEasyUiController;
import org.abyss.data.specifications.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.entity.system.SysUser;
import edu.tgc.entity.teaching.Enroll;
import edu.tgc.security.SessionUserUtils;
import edu.tgc.service.teaching.EnrollService;
import edu.tgc.web.form.teaching.EnrollForm;

@Controller
@RequestMapping(value="/teaching/enroll")
public class EnrollController extends CommonCrudEasyUiController<Enroll, UUID, EnrollForm>{
	
	@Autowired
	private EnrollService service;
	@Override
	public Specification<Enroll> buildSearch(EnrollForm form) {
		HashSet<Rule> rules=new HashSet<>();
		SysUser creator = form.getCreator();
		if(creator!=null){
			rules.add(Rule.property("creator.id").equal(creator.getId()));
		}
		String searchKey = form.getSearchKey();
		if(StringUtils.hasText(searchKey)){
			rules.add(Rule.property("name").contain(searchKey));
		}
		Boolean endTimeBool = form.getEndTimeBool();
		if(endTimeBool!=null&&endTimeBool){
			rules.add(Rule.property("endTime").greaterThan(new Date()));
		}
		return Rule.and(rules).toSpecification();
	}

	@RequestMapping(value="/combo")
	@ResponseBody
	public Object combo(){
		List<HashMap<String, Object>> list=service.combo();
		return list;
	}
	
}
